﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel.Channels;
using System.ServiceModel.Description;
using System.ServiceModel.Dispatcher;
using System.Text;
using System.Threading.Tasks;

namespace Sern.Common
{
    /// <summary>
    /// Inject the expression serializing deserializing here.
    /// </summary>
    public class ExpressionSerializingEndPointBehavior : IEndpointBehavior
    {
        public void Validate(ServiceEndpoint endpoint){}

        public void AddBindingParameters(ServiceEndpoint endpoint, BindingParameterCollection bindingParameters){}

        public void ApplyDispatchBehavior(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher)
        {
            foreach(var operation in endpoint.Contract.Operations)
            {
                operation.Behaviors.Add(new ExpressionSerializingOperationBehavior());
            }
        }

        public void ApplyClientBehavior(ServiceEndpoint endpoint, ClientRuntime clientRuntime)
        {
            foreach (var operation in endpoint.Contract.Operations)
            {
                operation.Behaviors.Add(new ExpressionSerializingOperationBehavior());
            }
        }
    }
}
